package com.example.bausip;

import java.util.ArrayList;
import java.util.Calendar;

import android.os.Bundle;
import android.app.Activity;
import android.app.DatePickerDialog;
import android.app.Dialog;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.DatePicker;
import android.widget.ListView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.TextView;
import android.widget.Toast;

public class CourseStudentsActivity extends Activity {

	MyCustomAdapter dataAdapter = null;
	ArrayList<Student> students = new ArrayList<Student>();
	ArrayList<Item> StudentItems = new ArrayList<Item>();
	

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_course_students);
		setStudents();
		
	}
	public void getStudents(int department_id) {
		String serverURL = new myURL("read_courses.php"/*?id="+department_id*/,true).getURL();
		RZHelper p = new RZHelper(serverURL, this, "setCourses", true);
		p.get();
	}
	public void setStudents() {
		for(int i =0;i<10;i++)
		{
			students.add(
					new Student(i,"f "+i,"fath "+i,"l "+i)
					);
			if(i%2==0)
				students.get(i).setRegistered(true);
			
		}
		//students = new APIManager().getCategories(s);
		StudentItems = new ArrayList<Item>();

		ListView listView = (ListView) findViewById(R.id.studentlist);

		listView.setTextFilterEnabled(true);

		String catUrl = null;
		if (students.size() == 0) {
			Item i = new Item("empty");
			i.setEmpty(true);
			StudentItems.add(i);
		} else {
			for (int i = 0; i < students.size(); i++) {
				
				StudentItems.add(new Item(students.get(i).getId(), catUrl,
						students.get(i).toString(), students.get(i)
								.isRegistered()));
			}
			registerForContextMenu(listView);
		}
		dataAdapter = new MyCustomAdapter(this, R.layout.name_list,
				StudentItems);
		if (students.size() == 0) {
			dataAdapter.empty = true;
		}
		SharedMenu.adapter = dataAdapter;
		listView.setAdapter(dataAdapter);

		listView.setOnItemClickListener(new OnItemClickListener() {

			public void onItemClick(AdapterView<?> parent, View view,
					int position, long id) {
				Intent i = new Intent(getBaseContext(), AddStudentActivity.class);
				//ontimedeliv.setStudentId(dataAdapter.tmpList.get(position)
				//		.getId());
				startActivity(i);

			}
		});
		/*
		serverURL = new myURL("activate_students", "branches", branchId, 0)
				.getURL();
		activate = new RZHelper(serverURL, this, "afterActivate", false);

		serverURL = new myURL("deactivate_students", "branches", branchId, 0)
				.getURL();
		deactivate = new RZHelper(serverURL, this, "afterActivate", false);
	*/
	}
	
	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.course_students, menu);
		return true;
	}

}
